<?php
/*
 * template/new-disponibilite.phtml
 */
?>
<?php

use RHX\Helper\RHDateTime;

// Variables
$site		 = $this->site;
$employes	 = $this->employes;
$codec		 = $this->codec;
$prefix		 = array(
    'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche',
);
?>
<div class='content-head'>
    <form id='new-empty' action='#' method='post'>
	<h3>
	    Planning Type : <input type='text' name='libelle' value='<?php echo 'Planning Type ' . $site->libelle ?>' style='width: 400px'>
	</h3>
	<div class='toolbar'>
	    <button class='btn btn-success saveNew'>Enregistrer</button>
	    <button class='btn btn-inverse goback'>Annuler</button>
	</div>
	<input type="hidden" name="site" value="<?php echo $site->id; ?>">
	<?php foreach ($employes as $e): ?>
	<!-- Employe #<?php echo $e->matricule; ?> -->
	    <?php
	    $dispo		 = $e->getDisponibilite();
	    $dispoArray	 = $dispo->getArrayCopy();
    //	    var_dump($dispoArray);
    ?>
        	<input type='hidden' id='new-<?php echo $e->matricule; ?>' name='employes[<?php echo $e->matricule; ?>]' value='<?php echo $e->matricule; ?>'>
    <?php for ($i = 0; $i < 7; $i++): ?>
			<!-- <?php echo $prefix[$i]; ?> -->
	<?php
	$code		 = $dispoArray[$prefix[$i]];
	$in		 = $dispoArray[$prefix[$i] . '_entree'];
	$out		 = $dispoArray[$prefix[$i] . '_sortie'];
	$pause		 = 0;
	$repas		 = 0;
	// Variable temporelle
	$entree		 = new RHDateTime();
	$entree->setTime($in);
	$sortie		 = new RHDateTime();
	$sortie->setTime($out);
	// Déterminaison si Pause et Repas
	$refDuree	 = new RHDateTime();
	$refDuree->setTime('05:00');
	$h12		 = new RHDateTime();
	$h12->setTime('12:00');
	$h14		 = new RHDateTime();
	$h14->setTime('14:00');
	$diffHeure	 = RHDateTime::diffHours($out, $in);
	$diff		 = new RHDateTime();
	$diff->setTime($diffHeure);
	if ($diff->isGT($refDuree)) {
	    // Plus de 5 heures
	    $pause = 1;
	}
	if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	    // Entre 12h et 14h
	    $pause	 = 1;
	    $repas	 = 1;
	}
	?>
			<input type='hidden' id='new-<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-code' name='<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-code' value='<?php echo $code; ?>'>
			<input type='hidden' id='new-<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-entree' name='<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-entree' value='<?php echo $entree->hours(); ?>'>
			<input type='hidden' id='new-<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-sortie' name='<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-sortie' value='<?php echo $sortie->hours(); ?>'>
			<input type='hidden' id='new-<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-pause' name='<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-pause' value='<?php echo $pause; ?>'>
			<input type='hidden' id='new-<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-repas' name='<?php echo $e->matricule; ?>-<?php echo $prefix[$i]; ?>-repas' value='<?php echo $repas; ?>'>
    <?php endfor; ?>
<?php endforeach; ?>
    </form>
</div>

<div class='content-body'>
    <div class='small-font'>
	<table class='table list-table'>
	    <thead>
		<tr>
		    <td rowspan='2'>Mat.</td>
		    <td rowspan='2'>Poste</td>
		    <td rowspan='2'>Nom</td>
		    <td colspan='5'>Lundi</td>
		    <td colspan='5'>Mardi</td>
		    <td colspan='5'>Mercredi</td>
		    <td colspan='5'>Jeudi</td>
		    <td colspan='5'>Vendredi</td>
		    <td colspan='5'>Samedi</td>
		    <td colspan='5'>Dimanche</td>
		    <td rowspan="2">Cumul des heures</td>
		</tr>
		<tr class='small-font'>
		    <!-- lundi -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		    <!-- mardi -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		    <!-- mercredi -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		    <!-- jeudi -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		    <!-- vendredi -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		    <!-- samedi -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		    <!-- dimanche -->
		    <td>Code</td>
		    <td>Entrée</td>
		    <td>Sortie</td>
		    <td>P</td>
		    <td>R</td>
		</tr>
	    </thead>
	    <tbody>
		<?php
		$jaune		 = 1;
		$refDuree	 = new RHDateTime();
		$refDuree->setTime('05:00');
		$h12		 = new RHDateTime();
		$h12->setTime('12:00');
		$h14		 = new RHDateTime();
		$h14->setTime('14:00');
		?>
		<?php foreach ($employes as $e) : ?>
		    <?php
		    $poste		 = $e->getPoste();
		    $dispo		 = $e->getDisponibilite();
		    ?>
		<tr>
    		    <td<?php echo (($jaune % 2) == 0) ? ' class="jaune2"' : ' class="jaune1"'; ?>><?php echo $e->matricule; ?></td>
    		    <td<?php echo (($jaune % 2) == 0) ? ' class="jaune2"' : ' class="jaune1"'; ?>><?php echo $poste->code; ?></td>
    		    <td<?php echo (($jaune % 2) == 0) ? ' class="jaune2"' : ' class="jaune1"'; ?>><?php echo $e->prenom; ?></td>

		    <!-- lundi -->
    		    <td class='<?php echo $codec[$dispo->lundi]; ?>' id='<?php echo $e->matricule; ?>-lundi-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='lundi'><?php echo $codec[$dispo->lundi]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->lundi]; ?>' id='<?php echo $e->matricule; ?>-lundi-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='lundi'><?php echo RHDateTime::hourNoSecond($dispo->lundi_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->lundi]; ?>' id='<?php echo $e->matricule; ?>-lundi-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='lundi'><?php echo RHDateTime::hourNoSecond($dispo->lundi_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->lundi_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->lundi_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->lundi_sortie, $dispo->lundi_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
        		    <td class='<?php echo $codec[$dispo->lundi]; ?>' id='<?php echo $e->matricule; ?>-lundi-pause'>
        			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='lundi'><?php echo $pause; ?></a>
        		    </td>
        		    <td class='<?php echo $codec[$dispo->lundi]; ?>' id='<?php echo $e->matricule; ?>-lundi-repas'>
        			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='lundi'><?php echo $repas; ?></a>
        		    </td>

		    <!-- mardi -->
    		    <td class='<?php echo $codec[$dispo->mardi]; ?>' id='<?php echo $e->matricule; ?>-mardi-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mardi'><?php echo $codec[$dispo->mardi]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->mardi]; ?>' id='<?php echo $e->matricule; ?>-mardi-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mardi'><?php echo RHDateTime::hourNoSecond($dispo->mardi_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->mardi]; ?>' id='<?php echo $e->matricule; ?>-mardi-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mardi'><?php echo RHDateTime::hourNoSecond($dispo->mardi_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->mardi_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->mardi_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->mardi_sortie, $dispo->mardi_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
    		    <td class='<?php echo $codec[$dispo->mardi]; ?>' id='<?php echo $e->matricule; ?>-mardi-pause'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mardi'><?php echo $pause; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->mardi]; ?>' id='<?php echo $e->matricule; ?>-mardi-repas'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mardi'><?php echo $repas; ?></a>
    		    </td>

		    <!-- mercredi -->
    		    <td class='<?php echo $codec[$dispo->mercredi]; ?>' id='<?php echo $e->matricule; ?>-mercredi-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mercredi'><?php echo $codec[$dispo->mercredi]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->mercredi]; ?>' id='<?php echo $e->matricule; ?>-mercredi-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mercredi'><?php echo RHDateTime::hourNoSecond($dispo->mercredi_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->mercredi]; ?>' id='<?php echo $e->matricule; ?>-mercredi-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mercredi'><?php echo RHDateTime::hourNoSecond($dispo->mercredi_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->mercredi_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->mercredi_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->mercredi_sortie, $dispo->mercredi_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
    		    <td class='<?php echo $codec[$dispo->mercredi]; ?>' id='<?php echo $e->matricule; ?>-mercredi-pause'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mercredi'><?php echo $pause; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->mercredi]; ?>' id='<?php echo $e->matricule; ?>-mercredi-repas'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='mercredi'><?php echo $repas; ?></a>
    		    </td>

		    <!-- jeudi -->
    		    <td class='<?php echo $codec[$dispo->jeudi]; ?>' id='<?php echo $e->matricule; ?>-jeudi-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='jeudi'><?php echo $codec[$dispo->jeudi]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->jeudi]; ?>' id='<?php echo $e->matricule; ?>-jeudi-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='jeudi'><?php echo RHDateTime::hourNoSecond($dispo->jeudi_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->jeudi]; ?>' id='<?php echo $e->matricule; ?>-jeudi-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='jeudi'><?php echo RHDateTime::hourNoSecond($dispo->jeudi_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->jeudi_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->jeudi_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->jeudi_sortie, $dispo->jeudi_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
    		    <td class='<?php echo $codec[$dispo->jeudi]; ?>' id='<?php echo $e->matricule; ?>-jeudi-pause'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='jeudi'><?php echo $pause; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->jeudi]; ?>' id='<?php echo $e->matricule; ?>-jeudi-repas'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='jeudi'><?php echo $repas; ?></a>
    		    </td>

		    <!-- vendredi -->
    		    <td class='<?php echo $codec[$dispo->vendredi]; ?>' id='<?php echo $e->matricule; ?>-vendredi-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='vendredi'><?php echo $codec[$dispo->vendredi]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->vendredi]; ?>' id='<?php echo $e->matricule; ?>-vendredi-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='vendredi'><?php echo RHDateTime::hourNoSecond($dispo->vendredi_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->vendredi]; ?>' id='<?php echo $e->matricule; ?>-vendredi-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='vendredi'><?php echo RHDateTime::hourNoSecond($dispo->vendredi_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->vendredi_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->vendredi_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->vendredi_sortie, $dispo->vendredi_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
    		    <td class='<?php echo $codec[$dispo->vendredi]; ?>' id='<?php echo $e->matricule; ?>-vendredi-pause'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='vendredi'><?php echo $pause; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->vendredi]; ?>' id='<?php echo $e->matricule; ?>-vendredi-repas'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='vendredi'><?php echo $repas; ?></a>
    		    </td>

		    <!-- samedi -->
    		    <td class='<?php echo $codec[$dispo->samedi]; ?>' id='<?php echo $e->matricule; ?>-samedi-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='samedi'><?php echo $codec[$dispo->samedi]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->samedi]; ?>' id='<?php echo $e->matricule; ?>-samedi-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='samedi'><?php echo RHDateTime::hourNoSecond($dispo->samedi_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->samedi]; ?>' id='<?php echo $e->matricule; ?>-samedi-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='samedi'><?php echo RHDateTime::hourNoSecond($dispo->samedi_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->samedi_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->samedi_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->samedi_sortie, $dispo->samedi_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
    		    <td class='<?php echo $codec[$dispo->samedi]; ?>' id='<?php echo $e->matricule; ?>-samedi-pause'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='samedi'><?php echo $pause; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->samedi]; ?>' id='<?php echo $e->matricule; ?>-samedi-repas'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='samedi'><?php echo $repas; ?></a>
    		    </td>

		    <!-- dimanche -->
    		    <td class='<?php echo $codec[$dispo->dimanche]; ?>' id='<?php echo $e->matricule; ?>-dimanche-code'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='dimanche'><?php echo $codec[$dispo->dimanche]; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->dimanche]; ?>' id='<?php echo $e->matricule; ?>-dimanche-entree'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='dimanche'><?php echo RHDateTime::hourNoSecond($dispo->dimanche_entree); ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->dimanche]; ?>' id='<?php echo $e->matricule; ?>-dimanche-sortie'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='dimanche'><?php echo RHDateTime::hourNoSecond($dispo->dimanche_sortie); ?></a>
    		    </td>
			<?php
			$entree		 = new RHDateTime();
			$entree->setTime($dispo->dimanche_entree);
			$sortie		 = new RHDateTime();
			$sortie->setTime($dispo->dimanche_sortie);
			$pause		 = '';
			$repas		 = '';
			$diff		 = new RHDateTime();
			$diffTime	 = RHDateTime::diffHours($dispo->dimanche_sortie, $dispo->dimanche_entree);
			$diff->setTime($diffTime);
			if ($diff->isGT($refDuree)) {
			    $pause = 'X';
			}
			if ($entree->isBetween($h12, $h14) || $sortie->isBetween($h12, $h14) || $h12->isBetween($entree, $sortie) || $h14->isBetween($entree, $sortie)) {
	$pause	 = 'X';
			    $repas	 = '1';
			}
			?>
    		    <td class='<?php echo $codec[$dispo->dimanche]; ?>' id='<?php echo $e->matricule; ?>-dimanche-pause'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='dimanche'><?php echo $pause; ?></a>
    		    </td>
    		    <td class='<?php echo $codec[$dispo->dimanche]; ?>' id='<?php echo $e->matricule; ?>-dimanche-repas'>
    			<a href='editer planning Type' class='template-edit' data-matricule='<?php echo $e->matricule ?>' data-prefix='dimanche'><?php echo $repas; ?></a>
		    </td>
    		    <td<?php echo (($jaune % 2) == 0) ? ' class="jaune2"' : ' class="jaune1"'; ?>>
    			<span id='<?php echo $e->matricule ?>-cumul'></span>
    		    </td>

		</tr>
		    <?php $jaune++; ?>
		<?php endforeach; ?>
	    </tbody>
	</table>
    </div>
</div>

<script type='text/javascript'>
    // Démarrage
    $(function() {
	// Retour
	$('.goback').click(function(e) {
	    e.preventDefault();
	    normalScreenLayout();
	});

	// Enregistrer
	$('.saveNew').click(function(e) {
	    e.preventDefault();
	    $('.saveNew').addClass('waiting-icon').text('');
//	    return false;
	    ajax = $.ajax({
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'saveEmpty')) ?>',
		data: $('#new-empty').serialize()
	    });
	    ajax.done(function() {
		//normalScreenLayout();
		window.location = "<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'index', 'id'		 => $site->id, 'other1'	 => 1, 'other2'	 => '1', 'other3'	 => 30)); ?>";
	    });
	    ajax.fail(function() {
		alert("Erreur");
	    });
	});

	// Editer
	$('.template-edit').click(function(event) {
	    event.preventDefault();
	    // Popin
	    // Récupération des variables
	    matricule = $(this).attr('data-matricule');
	    prefix = $(this).attr('data-prefix');

	    // Position de la souris
	    x = event.pageX;
	    y = event.pageY;
	    // Taille de l'écran
	    sw = $(window).width();
	    sh = $(window).height();
	    // Taille du dialogue
	    dw = 500;
	    dh = 400;
	    // Positionnement du dialogue
	    px = 0;
	    py = 0;
	    // Test sur la largeur
	    if ((sw - (dw + x)) > 0) {
		px = x;
	    } else {
		px = x - dw;
	    }
	    // Test sur la hauteur
	    if ((sh - y) >= dh - 400) {
		py = y /*- 40*/;
	    } else {
		py = y - dh /*+ 80*/;
	    }
	    // Suppression des autres DIV conteneur
	    $('.rhPopover').remove();
	    // Ajout d'un div conteneur
	    $('#' + matricule + '-' + prefix + '-code').append("<div class='rhPopover'></div>");
	    // Chargement du contenu
	    ajax = $.ajax({
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'newPopinEmpty')) ?>',
		data: "&prefix=" + prefix + '&matricule=' + matricule
	    });
	    ajax.success(function(data) {
		$('.rhPopover').hide().html(data).css({
		    'top': py,
		    'left': px
		}).show('normal');
	    });
	    ajax.error(function() {
		alert("Erreur de chargement");
	    });
	});

	// Clic Outside
	// Détecter clic en dehors du DIV
	$(document).mouseup(function(e) {
	    var container = $(".rhPopover");
	    if (container.has(e.target).length === 0) {
		// Suppression du DIV
		container.remove();
	    }
	});
    });
</script>

<style type='text/css'>
    .small-font{
	font-size: 0.8em;
    }
    <?php
    foreach ($this->colors as $key => $value) {
	echo ".$key {background: $value}\n";
    }
    ?>
    .jaune1{
	background: #FFF67F;
    }
    .jaune2{
	background: #FFEE05;
    }
    .table a{
	color: #080808;
    }
    .waiting-icon{
	width: 2em;
	height: 2em;
    }
</style>